#!/bin/sh
sshuser_nuc="www"
sshport_nuc="22"
sitelist_nuc=("192.168.3.11")


sshuser_prod="www"
sshport_prod="8015"
sitelist_prod=("stockor.zinbiz.com")

cho_env="nuc"
read -p "选择编译和部署环境Choose Environment:[nuc/prod](default:nuc): " cho_env
echo "选择编译和部署环境为:$cho_env Choose Environment:$cho_env"
case $cho_env in
    nuc)
        sshuser=$sshuser_nuc
        sshport=$sshport_nuc
        sitelist=(`echo ${sitelist_nuc[*]}`);;
    *)
        sshuser=$sshuser_prod
        sshport=$sshport_prod
        sitelist=(`echo ${sitelist_prod[*]}`);;        
    xxx)  echo "Choose Error, Exit!"
        exit;;
esac

echo 服务运行用户 $sshuser
echo 站点数量 ${#sitelist[*]}, 站点清单 "${sitelist[@]}"




for site in "${sitelist[@]}";do

    read -n 1 -p "是否部署资源文件 Deploy resource on $site? [Y/N](default:Y): " cho
    case $cho in
          N|n)echo "跳过 Skip...";;
        *)echo
            echo "开始部署资源文件 Start deploy resource on $site"
            ssh -p $sshport $sshuser@$site 'rm -rf /home/z/www/stockorboot-fe/*'
            scp -P $sshport -r ./assets/ ./data/ index.html $sshuser@$site:/home/z/www/stockorboot-fe/
            ssh -p $sshport $sshuser@$site 'echo var sys_version =\"`date +"r-%Y%m%d-%H%M%S"`\" > /home/z/www/stockorboot-fe/assets/js/version.js'
            echo "在$site上部署资源文件完成";;
    esac

done
read -n 1 -p "是否创建git tag? [Y/N](default:N): " cho
case $cho in
  Y|y)
    git tag -a `date +"r-%Y%m%d-%H%M%S-wanghaitao"` -m "`date +"r-%Y%m%d-%H%M%S-wanghaitao"`";;
  *)
    echo "跳过 Skip...";;
esac

echo '全部完成 Finished!'
